package com.spc.car.data.domain.attach.po;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.spc.car.common.utils.StringUtils;
import com.spc.car.data.entity.sys.SysAttachment;
import com.spc.car.data.util.PageParam;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Date;

@Data
@Accessors(chain = true)
public class AttachFilePO<T> extends PageParam<T> {

    /**作者*/
    private String FileOwner;

    /**文件编码*/
    private String fileCode;

    /**文件名称*/
    private String fileName;

    /**类别*/
    private String catalog;

    /**范围*/
    private String ranges;

    /**开始时间*/
    @JsonFormat(pattern = "yyyy-MM-DD HH:mm:ss")
    private Date beginTime;

    /**结束时间*/
    @JsonFormat(pattern = "yyyy-MM-DD HH:mm:ss")
    private Date endTime;

    /**构造Wrapper查询条件*/
    public Wrapper toWrapper() {
        QueryWrapper<SysAttachment> wrapper = new QueryWrapper<>();
        wrapper.eq("file_owner", FileOwner)
                .eq(StringUtils.isNotBlank(fileCode), "file_code", fileCode)

                .like(StringUtils.isNotBlank(fileName), "file_name", fileName)

                .eq(StringUtils.isNotBlank(catalog), "catalog", catalog)

                .eq(StringUtils.isNotBlank(ranges), "ranges", ranges)

                .ge(ObjectUtils.isNotNull(beginTime), "create_time", beginTime)

                .le(ObjectUtils.isNotNull(endTime), "create_time", endTime)

                .orderByDesc("create_time");

        return wrapper;
    }
}
